package com.yf.ability.login.wechat.service.impl;


import com.yf.ability.login.wechat.config.WechatConfig;
import com.yf.ability.login.wechat.dto.response.WxInfoRespDTO;
import com.yf.ability.login.wechat.dto.response.WxLoginRespDTO;
import com.yf.ability.login.wechat.service.WxLoginService;
import com.yf.ability.login.wechat.utils.LoginUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户登录业务类
 * @author bool
 */
@Log4j2
@Service
public class WxLoginServiceImpl implements WxLoginService {


    @Autowired
    private WechatConfig wechatConfig;


    @Override
    public WxLoginRespDTO login(String code, String nickName, String avatar) {

        // 转换为登录结果
        WxLoginRespDTO rest = LoginUtils.requestLogin(wechatConfig.getMpAppId(), wechatConfig.getMpAppSecret(), code);

        // 登录并返回
        return rest;
    }

    @Override
    public WxInfoRespDTO webLogin(String code) {
        WxInfoRespDTO rest = LoginUtils.requestInfo(wechatConfig.getSiteAppId(), wechatConfig.getSiteAppSecret(), code);
        // 登录并返回
        return rest;
    }
}
